﻿
@{
    Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}
@model OL.FrameCore.Application.Module.Dto.GetModuleResponse
@section CSS{

}

<form class="layui-form" id="DeptForm">
    <div class="layui-tab-content page-detail">
        <div class="layui-tab-item layui-show">
            <input type="hidden" id="hidId" value="@Model.Id" />
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">模块名称<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="tbModuleName" name="tbModuleName" lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input" value="@Model.ModuleName">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">模块编号<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="tbModuleCode" name="tbModuleCode" lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input" value="@Model.ModuleCode">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">父级模块<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <select id="selectParentId" lay-verify="required" lay-search="">
                            <option value="0">根目录</option>
                            @if (ViewBag.ModuleList != null)
                            {
                                foreach (var li in ViewBag.ModuleList)
                                {
                                    if (li.Id == Model.ParentId)
                                    {
                                        <option value="@li.Id" selected>@li.Name</option>
                                    }
                                    else
                                    {
                                        <option value="@li.Id">@li.Name</option>
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">是否菜单<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <input type="radio" name="isMenu" value="1" title="是" @(Model.IsMenu?"checked":"")>
                        <input type="radio" name="isMenu" value="0" title="否" @(Model.IsMenu==false?"checked":"")>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">Url<span class="required">&nbsp;</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="tbUrl" name="tbModuleCode" lay-verify="maxLength200" placeholder="" autocomplete="off" class="layui-input" value="@Model.MenuPath">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">图标<span class="required">&nbsp;</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="tbIcon" name="tbModuleCode" lay-verify="maxLength20" placeholder="" autocomplete="off" class="layui-input" value="@Model.Icon">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">排序<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="tbSortIndex" name="tbSortIndex" lay-verify="number" placeholder="" autocomplete="off" class="layui-input" value="@Model.SortIndex">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">备注<span class="required">&nbsp;</span></label>
                    <div class="layui-input-block">
                        <input type="text" id="tbRemark" name="tbRemark" lay-verify="maxLength200" placeholder="" autocomplete="off" class="layui-input" value="@Model.Remark">
                    </div>
                </div>
            </div>
            <div class="layui-row detail-submit">
                <div class="layui-layer-btn layui-layer-btn-c">
                    <a class="layui-layer-btn0" id="btnSave" lay-submit lay-filter="*">保存</a>
                    <a class="layui-layer-btn0" id="btnCanel" onclick="ModuleAddOrUpdate.cancel()">取消</a>
                </div>
            </div>
        </div>
    </div>
</form>

@section Scripts{
    <script>
        var ModuleAddOrUpdate = function () {
            let inited = false;
            let data = {};

            function initData() {
                layui.use(['form', 'layer'], function () {
                    var form = layui.form;
                    form.verify({
                        maxLength20: [/^.{0,20}$/, '长度最大为20'],
                        maxLength200: [/^.{0,200}$/, '长度最大为200']
                    });

                    form.on('submit(*)', function (data) {

                        var id = $("#hidId").val();
                        var moduleName = $("#tbModuleName").val();
                        var moduleCode = $("#tbModuleCode").val();
                        var parentId = $("#selectParentId").val();
                        var isMenu = $("input[name='isMenu']:checked").val();
                        var menuPath = $("#tbUrl").val();
                        var icon = $("#tbIcon").val();
                        var sortIndex = $("#tbSortIndex").val();
                        var remark = $("#tbRemark").val();

                        var type = id == 0 ? "添加" : "修改";

                        //开启loading
                        layer = layui.layer;
                        var index = layer.load(2);
                        $.ajax({
                            url: "/Module/PostAddOrUpdateModule",
                            type: "POST",
                            data: {
                                id: id,
                                moduleName: moduleName,
                                moduleCode: moduleCode,
                                parentId: parentId,
                                isMenu: isMenu==1,
                                menuPath: menuPath,
                                icon: icon,
                                sortIndex: sortIndex,
                                remark: remark
                            },
                            success: function (data) {
                                layer.close(index)
                                if (data.state == 1) {
                                    parent.layer.msg(type + "成功", { shade: 0.1, icon: 1 }, function () {
                                        //parent.location.reload();
                                        //刷新列表
                                        parent.layui.table.reload("table-list")
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    });
                                } else if (data.state == 0) {
                                    parent.layer.open({
                                        title: '提示'
                                        , content: type + "失败 " + data.msg
                                        , shade: 0.4
                                        , icon: 5
                                    });
                                } else {
                                    parent.layer.open({
                                        title: '提示'
                                        , content: type + "异常 " + data.msg
                                        , shade: 0.4
                                        , icon: 2
                                    });
                                }
                            }
                        });
                    });


                });
            }

            return {
                init() {//初始化
                    if (!inited) {
                        initData();
                        inited = true;
                    }
                },
                cancel() {//取消
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            };
        }();
        ModuleAddOrUpdate.init();
    </script>
}
